home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / pt20pc.zip / BUTTON.C < prev    next >
C/C++ Source or Header  |  1991-02-04  |  14KB  |  565 lines

  1. #include "pt.h"
  2. #include "stdlib.h"
  3.  
  4. /* delay to start scrolling */
  5. static int hsecToWait;
  6.  
  7. int pascal
  8. /* XTAG:mouseButton */
  9. mouseButton(evhead)
  10.     int evhead;
  11. {
  12.     extern unsigned char msgBuffer[];
  13.     extern union REGS rin, rout;
  14.     extern int menuRow, menuCol;
  15.     extern struct menuBlock far *menus[];
  16.     extern int debug;
  17.     extern struct window *selWindow;
  18.     extern long selBegin, selEnd;
  19.     extern struct window *activeWindow;
  20.     extern int scrRows, scrCols;
  21.     extern struct event events[];
  22.     extern unsigned char buttonVector[];
  23.     extern unsigned char toplineVector[];
  24.     extern int passEvhead;
  25.     extern long passCp;
  26.     extern int mousePresent;
  27.     extern int menuLine;
  28.     extern int helpMode;
  29.     extern int descrFileId;
  30.     extern int menuShowing;
  31.     extern int lastOnTopline;
  32.     extern int lastCommand;
  33.     extern int isMessage;
  34.     extern int searchMode;
  35.     extern int smoothScroll;
  36.     extern int scrollDelay;
  37.     extern unsigned char windowPoints[];
  38.     extern struct openFile *files;
  39.     extern unsigned char *outOfWindows;
  40.     extern int toplineMenu;
  41.  
  42.     struct window *w;
  43.     struct window  *newW;
  44.     int anchorRow, anchorCol, curRow, curCol;
  45.     int row1, col1, row2, col2;
  46.     int where, buttons, i, n, fid;
  47.     int menuNumber, buttonMask, thisShift, thisButton;
  48.     long cp, thumbcp, size;
  49.  
  50.     hsecToWait = scrollDelay;
  51.     anchorRow = events[evhead].vertical>>3;
  52.     anchorCol = events[evhead].horizontal>>3;
  53.     thisButton = events[evhead].buttons;
  54.     buttonMask = events[evhead].mask;
  55.     /* if no buttons down and not a mouse movement command */
  56.     /* thit it must be a left over button up event */
  57.     /* ignore left over button up events */
  58.     if( thisButton == 0 && buttonMask != 1 )
  59.         return 0;
  60.     if( thisButton == 0 ) {
  61.         /* is this the (top or bottom) menu line? */
  62.         if( anchorRow != (menuLine > 0 ? 0 : (scrRows-1) ) ) {
  63.             /* if we are displaying top line descriptions */
  64.             /* then erase them when you leave the top line */
  65.             if( helpMode > 1 && lastOnTopline == 1 ) {
  66.                 lastOnTopline = 0;
  67.                 msg("", 1);
  68.             }
  69.             return 0;
  70.         }
  71.  
  72.         /* if it is a menu, the figure out which item on it */
  73.         if( menuShowing != 0 ) {
  74.             n = FindMenuItem( menuShowing, anchorCol );
  75.             /* remember the last command selected */
  76.             lastCommand = n;
  77.             if( helpMode > 1 ) {
  78.                 readLine(descrFileId, 80L*(long)n,
  79.                             &msgBuffer[0], 0);
  80.                 msgBuffer[78] = '\0';
  81.                 msg(msgBuffer, 1);
  82.                 lastOnTopline = 1;
  83.             }
  84.         }
  85.         return 0;
  86.     }
  87.  
  88.     /* handle things that we need to do every command */
  89.     handleTempItems();
  90.  
  91.     switch( thisButton ) {
  92.         case 1:
  93.             buttons = LEFTBUTTON;
  94.             break;
  95.         case 2:
  96.             buttons = RIGHTBUTTON;
  97.             break;
  98.         case 3:
  99.         case 4:
  100.         default:
  101.             buttons = BOTHBUTTONS;
  102.             break;
  103.     }
  104.  
  105.     /* find out what window (if any) and where this mouse was */
  106.     xyToPos(&anchorRow, &anchorCol, &where, &cp, &w);
  107.     
  108.     /* set these now that anchorRow and anchorCol are set by xyToPos */
  109.     curRow = anchorRow;
  110.     curCol = anchorCol;
  111.  
  112.     /* execute the appropriate command for the mouse position */
  113.     /* and mouse buttons that were pressed */
  114.     switch( buttons+where ) {
  115.     
  116.     /* Any corner, Left => Top/Bottom */
  117.     case LEFTBUTTON+UPPERLEFT:
  118.         if( waitUp(1) )
  119.             goto bothUpperLeft;
  120.         else
  121.             return command(windowPoints[0], 0, w);
  122.     case LEFTBUTTON+LOWERLEFT:
  123.         if( waitUp(1) )
  124.             goto bothLowerLeft;
  125.         else
  126.             return command(windowPoints[4], 0, w);
  127.     case LEFTBUTTON+UPPERRIGHT:
  128.         if( waitUp(1) )
  129.             goto bothUpperRight;
  130.         else
  131.             return command(windowPoints[2], 0, w);
  132.     case LEFTBUTTON+LOWERRIGHT:
  133.         if( waitUp(1) )
  134.             goto bothLowerRight;
  135.         else
  136.             return command(windowPoints[6], 0, w);
  137.  
  138.     /* Any corner -- Right => Stretch Window */
  139.     case RIGHTBUTTON+UPPERLEFT:
  140.         row1 = w->row2;
  141.         col1 = w->col2;
  142.         goto allStretch;
  143.     case RIGHTBUTTON+UPPERRIGHT:
  144.         row1 = w->row2;
  145.         col1 = w->col1;
  146.         goto allStretch;
  147.     case RIGHTBUTTON+LOWERLEFT:
  148.         row1 = w->row1;
  149.         col1 = w->col2;
  150.         goto allStretch;
  151.     case RIGHTBUTTON+LOWERRIGHT:
  152.         row1 = w->row1;
  153.         col1 = w->col1;
  154.     allStretch:
  155.         if( getBox(row1, col1, &row1, &col1, &row2, &col2, 1) )
  156.             goto noAction;
  157.         /* move the window */
  158.         if( moveWindow(w, row1, col1, row2, col2) != 0 )
  159.             msg("Window too small, not changed", 1);
  160.         break;
  161.  
  162.     /* upper border, right button ==> move window */
  163.     case RIGHTBUTTON+UPPERBORDER:
  164.         row1 = w->row1;
  165.         col1 = w->col1;
  166.         row2 = w->row2;
  167.         col2 = w->col2;
  168.         if( getBox(curRow, curCol, &row1, &col1, &row2, &col2, 2) )
  169.             goto bothUpper;
  170.  
  171.         /* move the window */
  172.         if( moveWindow(w, row1, col1, row2, col2) != 0 )
  173.             msg("Window too small, not changed", 1);
  174.         break;
  175.  
  176.     /* Upper and Right, Both => Split Window */
  177.     case BOTHBUTTONS+UPPERBORDER:
  178.     bothUpper:
  179.         /* do the action on buttons up */
  180.         up2Buttons(&anchorRow, &anchorCol);
  181.         /* do not allow splits that are too small */
  182.         col2 = w->col2;    /* save this for the createWindow */
  183.         if( col2 < anchorCol + 10 || w->row2 < anchorRow + 2 ) {
  184.             msg("Split window too small, not created", 1);
  185.             break;
  186.         }
  187.         newW = createWindow(files[w->fileId].origName, anchorRow,
  188.             anchorCol, w->row2, col2, CRTOP, 0);
  189.         if( newW == NULL )
  190.             break;
  191.         newW->posTopline = w->posTopline;
  192.         newW->numTopline = w->numTopline;
  193.         newW->indent = w->indent;
  194.         redrawWindow(newW);
  195.         break;
  196.  
  197.     case BOTHBUTTONS+RIGHTBORDER:
  198.     bothRight:
  199.         /* do the action on buttons up */
  200.         up2Buttons(&anchorRow, &anchorCol);
  201.         /* do not allow splits that are too small */
  202.         row2 = w->row2;    /* save this for the createWindow */
  203.         if( anchorCol < w->col1 + 10 || row2 < anchorRow + 2 ) {
  204.             msg("Split window too small, not created", 1);
  205.             break;
  206.         }
  207.         newW = createWindow(files[w->fileId].origName, anchorRow,
  208.             w->col1, row2, anchorCol, CRTOP, 0);
  209.         if( newW == NULL )
  210.             break;
  211.         row1 = anchorRow+1;
  212.         col1 = w->col1+1;
  213.         newW->posTopline = xyToWindow(w, &row1, &col1);
  214.         newW->numTopline = w->numTopline + anchorRow - w->row1;
  215.         newW->indent = w->indent;
  216.         redrawWindow(newW);
  217.         break;
  218.  
  219.     /* Lower border, Left, Right => Scroll, Both => Thumb */
  220.     case LEFTBUTTON+LOWERBORDER:
  221.     moreRightScrolling:
  222.         if( !smoothScroll && waitUp(1) )
  223.             goto bothLower;
  224.         if( (where = anchorCol - w->col1 - 1) < 1 )
  225.             where = 1;
  226.         if( (w->indent -= where) < 0 )
  227.             w->indent = 0;
  228.         redrawWindow(w);
  229.         if( ScrollSomeMore() )
  230.             goto moreRightScrolling;
  231.         break;
  232.  
  233.     case RIGHTBUTTON+LOWERBORDER:
  234.     moreLeftScrolling:
  235.         if( !smoothScroll && waitUp(1) )
  236.             goto bothLower;
  237.         if( (where = anchorCol - w->col1 - 1) < 1 )
  238.             where = 1;
  239.         w->indent += where;
  240.         redrawWindow(w);
  241.         if( ScrollSomeMore() )
  242.             goto moreLeftScrolling;
  243.         break;
  244.  
  245.     case BOTHBUTTONS+LOWERBORDER:
  246.     bothLower:
  247.         /* do the action on buttons up */
  248.         up2Buttons(&anchorRow, &anchorCol);
  249.         where = anchorCol - w->col1 - 1;
  250.         w->indent = where;
  251.         redrawWindow(w);
  252.         break;
  253.  
  254.     /* Left border, left and right => scroll, both => thumb */
  255.     case LEFTBUTTON+LEFTBORDER:
  256.     rev1scr:
  257.         if( !smoothScroll && waitUp(1) )
  258.             goto bothLeft;
  259.         where = anchorRow - w->row1 - 1;
  260.         if( where < 1 )
  261.             where = 1;
  262.         /* set up the screen map and scroll the window */
  263.         setMap( w->row1, w->col1, w->row2, w->col2, 1, 0x07);
  264.         maskTop(w);
  265.         downScroll(w, where);
  266.         if( ScrollSomeMore() )
  267.             goto rev1scr;
  268.         break;
  269.  
  270.     case RIGHTBUTTON+LEFTBORDER:
  271.     rev2scr:
  272.         if( !smoothScroll && waitUp(1) )
  273.             goto bothLeft;
  274.         where = anchorRow - w->row1 - 1;
  275.         if( where < 1 )
  276.             where = 1;
  277.         /* set up the screen map and scroll the window */
  278.         setMap(w->row1, w->col1, w->row2, w->col2, 1, 0x7);
  279.         maskTop(w);
  280.         upScroll(w, where);
  281.         if( ScrollSomeMore() )
  282.             goto rev2scr;
  283.         break;
  284.  
  285.     case BOTHBUTTONS+LEFTBORDER:
  286.     bothLeft:
  287.         /* do the action on buttons up */
  288.         up2Buttons(&anchorRow, &anchorCol);
  289.         /* remember where we came from */
  290.         w->rowLastline = w->numTopline;
  291.  
  292.         fid = w->fileId;
  293.         size = fileSize(fid);
  294.         n = w->row2 - w->row1 - 2; /* find the size of the window */
  295.         where = anchorRow - w->row1 - 1;
  296.         if( where < 0 )
  297.             where = 0;
  298.         else if( where > n )
  299.             where = n;
  300.         /* handle going to EOF as a special case */
  301.         if( where  == n ) {
  302.             /* this puts the EOF mark on the bottom line */
  303.             i = n + 1;
  304.             thumbcp